package com.hitqz.robot.biz.flow.config;

import com.yomahub.liteflow.aop.ICmpAroundAspect;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CmpAspect implements ICmpAroundAspect {

    @Override
    public void beforeProcess(NodeComponent nodeComponent) {

    }

    @Override
    public void afterProcess(NodeComponent nodeComponent) {

    }

    @Override
    public void onSuccess(NodeComponent nodeComponent) {

    }

    @Override
    public void onError(NodeComponent nodeComponent, Exception e) {
        log.warn("捕捉到异常",e);
        // 外部中断，抛出异常，终止流程
        // 内部异常，继续执行，保持流程
        boolean continueFlag = true;
        if (e instanceof FlowInterruptException||e instanceof InterruptedException){
            continueFlag = false;
            log.info("结束整个工作流,当前工作流：{}",nodeComponent);
            nodeComponent.setIsEnd(true);
        }
        if (e instanceof DoorOpenException){
            continueFlag = false;
        }

        nodeComponent.setIsContinueOnError(continueFlag);

    }
}
